#@layoutT("配置角色用户")
#define css()
<style type="text/css">
.div-scroll{
	overflow:auto;
	border:1px solid #DCDCDC;
	min-height: 595px;
	min-width:345px;
	position: relative;
}
  .l-layout-header {
    position: relative;
    padding-left: 10px;
    color: #183152;
    font-weight: bold;
    height: 30px;
    line-height: 30px;
    background: #E5EFFE;
    overflow: hidden;
    cursor: pointer;
}
.layui-form-item .layui-inline {
    /* margin-bottom: 5px; */
    margin-right: 0px;
}
.f-form .layui-inline {
    margin-top: 3px;
    margin-bottom: 0px;
}
</style>
#end
#define main()
		<div class="layui-row layui-col-space1 task-row">
		  <div class="layui-col-xs6 div-scroll">
			 <div class="l-layout-header"><span style="color:#5FB878">#(roleName)</span> 可选用户</div>
             <div class="l-scroll"style="left: 0px;top: 0px;">
            	#@formStart()							
					<div class="layui-inline">																	
					   	<input type="search" name="userName" autocomplete="off" class="layui-input" placeholder="姓名"/>								
					</div>								
					<div class="layui-inline">
					   <select name="orgId" class="layui-input" lay-search>
					   		<option value="">请选择部门</option>
					   		#for(data:orgList)
			       			<option value="#(data.value??)">#(data.text??)</option>
			       			#end
					   </select>
					</div>			
				#@formEnd()				
           		<table id="maingrid" lay-filter="maingrid"></table>
             </div>
		</div>
		  
		  <div class="layui-col-xs6 div-scroll">
		  	<div class="l-layout-header"><span style="color:#5FB878"></span> 已选用户</div>
		  	<div class="l-scroll"style="left: 0px;top: 0px;">
		  		<form class="layui-form layui-form-pane f-form" id='searchForm1' lay-filter='searchForm1' action="javascript:;">
					<div class='layui-row layui-col-space1 task-row'>
						<div class='layui-col-xs12 '> 
							<div class="layui-form-item">
								<div class="layui-inline">																	
								   	<input type="search" name="userName" autocomplete="off" class="layui-input" placeholder="姓名"/>								
								</div>								
								<div class="layui-inline">
								   <select name="orgId" class="layui-input" lay-search>
								   		<option value="">请选择部门</option>
								   		#for(data:orgList)
						       			<option value="#(data.value??)">#(data.text??)</option>
						       			#end
								   </select>
								  </div>								
								<div class="layui-inline">
									<div class="layui-btn-group">
										<button class="layui-btn">
											<i class="layui-icon">&#xe615;</i>查询
										</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</form>
           		<table id="maingrid1" lay-filter="maingrid1"></table>
             </div>
		</div>
	</div>
	<!-- 	每行的操作按钮 -->
	<script type="text/html" id="bar_maingrid">
  	<a class="layui-btn layui-btn-xs" lay-event="add">选择</a>
	</script>
	<script type="text/html" id="bar_maingrid1">
	#if(roleCode=='superadmin')
  	<a class="layui-btn layui-btn-xs layui-btn-danger {{d.user_code=='superadmin'?"layui-disabled":""}}" lay-event="remove{{d.user_code=='superadmin'?"layui-disabled":""}}">移除</a>
	#elseif(roleCode=="admin")
	<a class="layui-btn layui-btn-xs layui-btn-danger {{d.user_code=='admin'?"layui-disabled":""}}" lay-event="remove{{d.user_code=='admin'?"layui-disabled":""}}">移除</a>
	#else
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="remove">移除</a>
	#end
	</script>
#end

#define js()
<!-- 分页表格 -->
<script>
	var roleCode="#(roleCode)";
	//选择用户
	 function addUser(obj){
		var data=obj.data;
		var userCode=data.user_code;
		var url="#(path)/portal/core/sysRole/saveRoleUser?isJson=true&userCode="+userCode+"&roleCode="+roleCode;
		$.ajax({
			url
			,type:"POST"
			,success:function(data){				
				$(".layui-laypage-btn").click();
				if(num==0){
					queryRoleUserList();
				}				
				layer.msg(data.msg);
			}
		});
	 }
	 //移除用户
	 function removeUser(obj){
		var data=obj.data;
		var userCode=data.user_code;
		var url="#(path)/portal/core/sysRole/deleteRoleUser?isJson=true&userCode="+userCode+"&roleCode="+roleCode;
		$.ajax({
			url
			,type:"POST"
			,success:function(data){
				refreshData();				
				layer.msg(data.msg);
			}
		});
	 }

	var num=0;
	//查询角色用户,是否重新渲染表格
	function queryRoleUserList(){
		var url="#(path)/portal/core/sysRole/queryRoleUserList?isJson=true&roleCode="+roleCode;
		$.ajax({
			 url
			 ,type:"POST"
			 ,success:function(data){
				 num=data.totalRow;
				 if(data.totalRow<=1){					
					table.reload('maingrid1', {});
				 }
			}
		});
	}
	//未选用户列表
	gridArgs.title='用户';
	gridArgs.dataId='id';
	gridArgs.gridDivId ='maingrid';
	initGrid({id : 'maingrid'
			,elem : '#maingrid'
			,cellMinWidth: 80
			,cols : [ [
					{title: '主键',field : 'id',width : 35,checkbox : true},						
					{title: '用户名', field: 'user_code',sort:true},
        			{title: '姓名', field: 'user_name',sort:true},
	        		{title: '所属部门', field: 'org_name',sort:true},																	
					{title: '操作',fixed:'right',width : 100,align : 'left',toolbar : '#bar_maingrid'} // 这里的toolbar值是模板元素的选择器
			] ]
			,url:"#(path)/portal/core/sysRole/queryUserListNotInRoleCode?roleCode="+roleCode
			,searchForm : 'searchForm'
		},{add:addUser});
	
	//已选用户列表
	initGrid({id : 'maingrid1'
			,elem : '#maingrid1'
			,cellMinWidth: 80
			,cols : [ [
					{title: '主键',field : 'id',width : 35,checkbox : true},						
					{title: '用户名', field: 'user_code',sort:true },
        			{title: '姓名', field: 'user_name',sort:true},
	        		{title: '所属部门', field: 'org_name',sort:true},																	
					{title: '操作',fixed:'right',width : 100,align : 'left',toolbar : '#bar_maingrid1'} // 这里的toolbar值是模板元素的选择器
			] ]
			,url:"#(path)/portal/core/sysRole/queryRoleUserList?roleCode="+roleCode
			,searchForm : 'searchForm1'
		},{remove:removeUser});
	
</script>
#end

  